﻿/*
 * Created by SharpDevelop.
 * User: obeyis
 * Date: 11/05/2015
 * Time: 10:53
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Linq;

namespace AnalysisEngine.Core
{
	public class GroupData
	{
		public Lookup<Row, Row> Lookup;
		public Dictionary<Row, Row> InverseLookup;
		
		public GroupData Parent;
		public List<Column> Columns ;
	}

    public class SelectionData
    {
        public Dictionary<Column, ColumnSelectionData> Columns = new Dictionary<Column, ColumnSelectionData>();

        public string Name;

        internal int[] Rows;
       
        public Book book;

        public SelectionData(Book book)
        {
            // TODO: Complete member initialization
            this.book = book;
        }

        public void UpdateRowSelection()
        {
            Array.Clear(Rows, 0, Rows.Length);

            foreach (var col in Columns )
            {
               var gcol=  book.Cache.GetGroupData(col.Key);

               foreach (var key in col.Value.SelectedKeys)
               {
                   foreach (var keyrow in gcol.Lookup[key])
                   {
                       this.Rows[keyrow.Index] += 1;
                   }
               }
            }
        }

        public bool IsRowSelected(Row row)
        {
            return Rows[row.Index] == Columns.Count;
        }
    }

    public class ColumnSelectionData
    {
        public List<Row> SelectedKeys = new List<Row>();

        public SelectionData selectionData;

        public ColumnSelectionData(SelectionData selectionData)
        {
            // TODO: Complete member initialization
            this.selectionData = selectionData;
        }

    }

    public class Key
    {
        Row Row;
        object[] Values;
        Column[] Columns;
    }
}
